// GlwHorizontalBar.cpp : implementation file
//

#include "stdafx.h"
#include "GlwHorizontalBar.h"


// GlwHorizontalBar

IMPLEMENT_DYNAMIC(GlwHorizontalBar, CAcUiDockControlBar)

BEGIN_MESSAGE_MAP(GlwHorizontalBar, CAcUiDockControlBar)
	ON_WM_PAINT()
	ON_WM_CREATE()
	ON_WM_ERASEBKGND()
	ON_MESSAGE(WM_ACAD_KEEPFOCUS, onAcadKeepFocus)
END_MESSAGE_MAP()

GlwHorizontalBar::GlwHorizontalBar() { }

GlwHorizontalBar::~GlwHorizontalBar() { }

LRESULT GlwHorizontalBar::onAcadKeepFocus( WPARAM wp, LPARAM lp )
{
	CRect rcWin;
	GetWindowRect(&rcWin);

	CPoint pt;
	::GetCursorPos(&pt);

	return  rcWin.PtInRect(pt) ? TRUE : FALSE;
}

BOOL GlwHorizontalBar::OnEraseBkgnd( CDC* pDC )
{
	return FALSE;
}

void GlwHorizontalBar::OnPaint()
{
	CPaintDC PaintDC(this);

	CRect rcBar;
	GetClientRect(&rcBar);

	CDC	dc;
	dc.CreateCompatibleDC(&PaintDC);

	CBitmap bm;
	bm.CreateCompatibleBitmap(&PaintDC, rcBar.Width(), rcBar.Height());
	dc.SelectObject(bm);
	dc.SetBoundsRect(&rcBar, DCB_DISABLE);

	// draw background
	CBrush brush(BK_COLOR);
	dc.FillRect(rcBar, &brush);

	PaintDC.BitBlt (rcBar.left, rcBar.top, rcBar.Width(), rcBar.Height(), &dc, 0,0,SRCCOPY);
	dc.DeleteDC ();
}

BOOL GlwHorizontalBar::Create( CWnd *pParentWnd, int height, bool bTop /*= true*/ )
{
	DWORD dwStyle = WS_CHILD | WS_VISIBLE | (bTop ? CBRS_TOP : CBRS_BOTTOM);

	CRect rect;
	pParentWnd->GetWindowRect(rect);

	BOOL bRet = CAcUiDockControlBar::Create(pParentWnd, NULL, -1, dwStyle, 
		CRect(0, 1, rect.Width(), height));

	ShowCloseButton(false);

	return bRet;
}

const int GlwHorizontalBar::BAR_HEIGHT = 200;

const DWORD GlwHorizontalBar::BK_COLOR = RGB(90, 107, 226);
